package com.hxzy.research.controller.admin;

import com.hxzy.research.pojo.TblUser;
import com.hxzy.research.service.pageandmanager.AdminUserLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping(value = "/admin")
public class UserHomeController {
    @Autowired private AdminUserLogin adminUserLogin;
    @RequestMapping("/userHome.go")
    //判断是否为管理员用户
    public String userHome(Model model,HttpSession session)throws Exception{
        //判断issuper是否为1
        String username=(String) session.getAttribute("username");
        TblUser tblUser=adminUserLogin.findUserByName(username);
        model.addAttribute("branchid",tblUser.getBranchid());
        if (tblUser.getBranchid().equals(0)){
            session.setAttribute("username",tblUser.getUsername());
            return "admin/adminindex";
        }else {
            session.setAttribute("username",tblUser.getUsername());
            return "admin/index";

        }
        //return null;
    }

    //用户退出功能
    @RequestMapping("/loginOut.go")
    public String loginOut(Model model,HttpSession session)throws Exception{
        session.getAttribute("username");
        //令session失效
        session.invalidate();
        return "redirect:/login.jsp";
    }
}
